package com.yanqu.road.entity.activity.biaoju;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.activity.biaoju.config.eBiaoJuEscortStatus;

import java.util.ArrayList;
import java.util.List;

@FieldTypeAnnotation(tableName = "t_c_biaoju_user_run", desc = "镖局玩家走镖的数据")
public class CrossBiaoJuUserRunEscortData extends DataObject {
    @FieldTypeAnnotation(select = true, update = true, isIndex = true)
    private int activityId;
    @FieldTypeAnnotation(update = true, isIndex = true)
    private long userId;
    @FieldTypeAnnotation(select = true, update = true, isIndex = true, desc = "商会分组")
    private int unionGroup;
    @FieldTypeAnnotation(update = true, isIndex = true)
    private int uniqueId;
    @FieldTypeAnnotation(desc = "接镖回合")
    private int round;
    @FieldTypeAnnotation(desc = "优质镖id")
    private int bestEscortId;
    @FieldTypeAnnotation(desc = "镖id")
    private int escortId;
    @FieldTypeAnnotation(desc = "目标城市id")
    private int cityId;
    @FieldTypeAnnotation(desc = "战力")
    private int battleValue;
    @FieldTypeAnnotation(desc = "当前血量")
    private int remainBlood;
    @FieldTypeAnnotation(desc = "接镖时间毫秒")
    private long takeTime;
    @FieldTypeAnnotation(desc = "走镖时间毫秒")
    private long runStartTime;
    @FieldTypeAnnotation(desc = "完成时间毫秒")
    private long finishTime;
    @FieldTypeAnnotation(desc = "加速的时间毫秒")
    private long speedUpTime;
    @FieldTypeAnnotation(desc = "队友")
    private List<BiaoJuTeamUserInfo> teamUserList = new ArrayList<>();
    @FieldTypeAnnotation(desc = "战斗记录,数量少且固定,放这里了")
    private List<BiaoJuEscortBattleLog> battleLogList = new ArrayList<>();
    @FieldTypeAnnotation(desc = "跑镖时的镖局等级")
    private int unionLevel;
    @FieldTypeAnnotation(desc = "跑镖时的镖头等级")
    private int userLevel;
    @FieldTypeAnnotation(desc = "跑镖时的城市加成")
    private int cityAddition;
    @FieldTypeAnnotation(desc = "奖励")
    private String reward = "";
    @FieldTypeAnnotation(desc = "队长奖励")
    private String leaderReward = "";

    public CrossBiaoJuUserRunEscortData() {
    }

    public CrossBiaoJuUserRunEscortData(int uniqueId, int activityId, long userId, int unionGroup, int escortId, int cityId, int bestEscortId, int round) {
        this.uniqueId = uniqueId;
        this.activityId = activityId;
        this.userId = userId;
        this.unionGroup = unionGroup;
        this.escortId = escortId;
        this.cityId = cityId;
        this.bestEscortId = bestEscortId;
        this.round = round;
        setInsertOption();
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public int getUnionGroup() {
        return unionGroup;
    }

    public void setUnionGroup(int unionGroup) {
        this.unionGroup = unionGroup;
    }

    public int getEscortId() {
        return escortId;
    }

    public void setEscortId(int escortId) {
        this.escortId = escortId;
    }

    public int getCityId() {
        return cityId;
    }

    public void setCityId(int cityId) {
        this.cityId = cityId;
    }

    public int getBattleValue() {
        return battleValue;
    }

    public void setBattleValue(int battleValue) {
        this.battleValue = battleValue;
        setUpdateOption();
    }

    public int getRemainBlood() {
        return remainBlood;
    }

    public void setRemainBlood(int remainBlood) {
        this.remainBlood = remainBlood;
        setUpdateOption();
    }

    public long getTakeTime() {
        return takeTime;
    }

    public void setTakeTime(long takeTime) {
        this.takeTime = takeTime;
        setUpdateOption();
    }

    public long getRunStartTime() {
        return runStartTime;
    }

    public void setRunStartTime(long runStartTime) {
        this.runStartTime = runStartTime;
        setUpdateOption();
    }

    public long getFinishTime() {
        return finishTime;
    }

    public void setFinishTime(long finishTime) {
        this.finishTime = finishTime;
        setUpdateOption();
    }

    public long getSpeedUpTime() {
        return speedUpTime;
    }

    public void setSpeedUpTime(long speedUpTime) {
        this.speedUpTime = speedUpTime;
        setUpdateOption();
    }

    public List<BiaoJuTeamUserInfo> getTeamUserList() {
        return teamUserList;
    }

    public void setTeamUserList(List<BiaoJuTeamUserInfo> teamUserList) {
        this.teamUserList = teamUserList;
        setUpdateOption();
    }

    public List<BiaoJuEscortBattleLog> getBattleLogList() {
        return battleLogList;
    }

    public void setBattleLogList(List<BiaoJuEscortBattleLog> battleLogList) {
        this.battleLogList = battleLogList;
        setUpdateOption();
    }

    public int getBestEscortId() {
        return bestEscortId;
    }

    public void setBestEscortId(int bestEscortId) {
        this.bestEscortId = bestEscortId;
        setUpdateOption();
    }

    public String getReward() {
        return reward;
    }

    public void setReward(String reward) {
        this.reward = reward;
        setUpdateOption();
    }


    public int getStatus() {
//  2:锁定中,被玩家刷到的 3:被接镖的 4:走镖中 5:已完成
        if (finishTime > 0) {
            return eBiaoJuEscortStatus.Finished.getValue();
        }
        if (runStartTime > 0) {
            return eBiaoJuEscortStatus.Running.getValue();
        }
        if (takeTime > 0) {
            return eBiaoJuEscortStatus.Taken.getValue();
        }
        return eBiaoJuEscortStatus.Locked.getValue();
    }

    public boolean isInTeam(long userId) {
        for (BiaoJuTeamUserInfo teamUserInfo : teamUserList) {
            if (teamUserInfo.getUserId() == userId) {
                return true;
            }
        }
        return false;
    }

    public void addTeamUser(long userId, int level) {
        BiaoJuTeamUserInfo teamUserInfo = new BiaoJuTeamUserInfo();
        teamUserInfo.setUserId(userId);
        teamUserInfo.setLevel(level);
        teamUserList.add(teamUserInfo);
        setUpdateOption();
    }

    public void removeTeamUser(long userId) {
        for (BiaoJuTeamUserInfo teamUserInfo : teamUserList) {
            if (teamUserInfo.getUserId() == userId) {
                teamUserList.remove(teamUserInfo);
                setUpdateOption();
                return;
            }
        }
    }

    public int getUnionLevel() {
        return unionLevel;
    }

    public void setUnionLevel(int unionLevel) {
        this.unionLevel = unionLevel;
        setUpdateOption();
    }

    public int getUserLevel() {
        return userLevel;
    }

    public void setUserLevel(int userLevel) {
        this.userLevel = userLevel;
        setUpdateOption();
    }

    public int getCityAddition() {
        return cityAddition;
    }

    public void setCityAddition(int cityAddition) {
        this.cityAddition = cityAddition;
        setUpdateOption();
    }

    public int getUniqueId() {
        return uniqueId;
    }

    public void setUniqueId(int uniqueId) {
        this.uniqueId = uniqueId;
    }

    public int getRound() {
        return round;
    }

    public void setRound(int round) {
        this.round = round;
        setUpdateOption();
    }

    public int getLoseNum() {
        int loseNum = 0;
        for (BiaoJuEscortBattleLog battleLog : this.getBattleLogList()) {
            if (battleLog.getRemainBlood() == 0) {
                loseNum++;
            }
        }
        return loseNum;
    }

    public String getLeaderReward() {
        return leaderReward;
    }

    public void setLeaderReward(String leaderReward) {
        this.leaderReward = leaderReward;
        setUpdateOption();
    }
}
